package com.dzh.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.deploy.net.HttpResponse;
import org.springframework.http.HttpRequest;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //登录截断器 判断用户是否登录
        Object LoginUser = request.getSession().getAttribute("loginUser");
        if(LoginUser==null){
            request.setAttribute("msg","你还未登录，请登录");
            request.getRequestDispatcher("/login.html").forward(request,response);
            return false;
        }
        else {
            return true;
        }
    }



}
